<style>
form .row{
_min-height: 25px;
	margin-bottom: 5px;
}
form .row label{
	width: 200px;
	height: 20px;
	font-weight: 600;
	font-style: italic;
	display: block;
	color: #4c4c4c;
}
form .row input,
form .row select{
}
form .row textarea{
	width: 300px;
	height: 100px;
}
form .buttons{
	float:left;
}

</style>
<script type="text/javascript">
$(document).ready(function(){
    $("#frmTag").submit(function(){
		var name = $("#name").attr("value");
		var link = $("#link").attr("value");
		var msg = "";
		if(name == ""){
			msg += "Thiếu tên tag.\n";
		}
		if(link == ""){
                msg+= "Thiếu link của tag.";
            }

		if(msg != ""){
			alert(msg);
			return false;
		}
	});
      //xóa
	$("#btnDelete").click(function(){
		var valid= false;
		var arrChkId = $(".chkId");
		var strIDs = "";
		for(var i =0; i < arrChkId.length; i++){
			if(arrChkId.eq(i).attr("checked")){
				valid = true;
				if(strIDs!=""){
					strIDs +=","+ arrChkId.eq(i).attr("value");
				}else{
					strIDs +=arrChkId.eq(i).attr("value");
				}
				//break;
			}
		}
		if(valid){
			if(confirm("Bạn thực sự muốn xóa những tag này?")){
				$("#hddIDs").attr("value", strIDs);
				
			}else{
				return false;
			}
		}else{
			alert("Xin hãy chọn tag muốn xóa!");
			return false;
		}
	});
});
</script>
<div id="r-heading">
	<img src="<?php echo PUBLIC_URL.'/admin/images/tag.png';?>" alt=""/>
	<span>Danh sách Tag</span>
</div>
<?php
//nếu có message thì hiển thị
if(!empty($this->message)){
	echo '<div id="message">'.$this->message.'</div>';
} 
?>

<form id="frmTag" method="post" action="">
	<div style="width: 40%; float: left;">
		<div class="row">
			<label for="name">Tên thẻ</label>
                  
			<input style="width: 200px;" type="text" name="name" id="name" size="30" value="<?php isset($this->tag) ? $this->tag->name : ""?>"/>
		</div>
		<div class="row">
			<label for="link">Link</label>
			<input style="width: 200px;" type="text" name="link" id="link" size="30" value="<?php isset($this->tag) ? $this->tag->link : ""?>"/>
		</div>
		<div class="row">
			<input class="button" type="submit" value="Lưu"/>
			<input class="button" type="reset" value="Làm lại"/>
		</div>
	</div>
</form>

<div style="width: 55%; float:left;">
	<form id="frmActions" action="<?php echo $this->url(array(),"admin_tag_delete");?>" method="post">
		<div id="actions">
			<input type="button" class="button" value="Thêm mới" onclick="location='<?php echo $this->url(array('id' => ''), 'admin_tag');?>';"/>
			<input type="submit" id="btnDelete" class="button" value="Xóa các mục đã chọn"/>
			<input type="hidden" id="hddIDs" value="" name="ids"/>
		</div>
		<table class="list" cellspacing="0">
			<thead>
				<tr>
					<td width="5%">
						<input type="checkbox" class="chkAll"/>
					</td>
					<td width="15%">
						Tên tag
					</td>
					<td width="55%">
						Link
					</td>
					<td width="15%">
						Thực hiện
					</td>
				</tr>
			</thead>
			<tbody>
				<?php
					$count = count($this->arrTags);
					if($count == 0){
				?>
					<tr>
						<td colspan="4" style="color: #fc0202;">
							Chưa có tag nào trong cơ sở dữ liệu!
						</td>
					</tr>
				<?php
					}else{
						for($i = 0; $i< $count; $i++){
				?>
					<tr <?php if($i == $count - 1) echo 'class="last"';?>>
						<td>
							
							<input type="checkbox" class="chkId" value="<?php echo $this->arrTags[$i]->id; ?>"/>
						</td>
						<td>
							
							<a href="<?php echo  $this->url(array('id' => $this->arrTags[$i]->id), 'admin_tag');?>" title="Sửa thông tin tag">
								<?php
									echo $this->arrTags[$i]->name;
								?>
							</a>
						</td>
						
						<td>
                                        	<a href="<?php echo $this->arrTags[$i]->link;?>"><?php echo $this->arrTags[$i]->link;?></a>
						</td>
						<td>
							<a href="<?= $this->url(array('id' => $this->arrTags[$i]->id), 'admin_tag');?>" title="Sửa thông tin tag">Sửa</a>
							|
							<a href="<?= $this->url(array('id' => $this->arrTags[$i]->id), 'admin_tag_delete');?>" onclick="if(!confirm('Bạn thực sự muốn xóa tag này')) return false;">Xóa</a>
						</td>
					</tr>
				<?php
						}
					}
				?>
			</tbody>
			<tfoot>
				<tr>
					<td>
						<input type="checkbox" class="chkAll"/>
					</td>
					<td>
						Tên tag
					</td>
					<td>
						Link
					</td>
					<td>
						Thực hiện
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</div>
